package com.yf.course.modules.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yf.course.modules.course.entity.CourseRefDir;
import com.yf.course.modules.course.mapper.CourseRefDirMapper;
import com.yf.course.modules.course.service.CourseRefDirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
* <p>
* 课程目录业务实现类
* </p>
*
* @author 聪明笨狗
* @since 2021-03-12 16:18
*/
@Service
public class CourseRefDirServiceImpl extends ServiceImpl<CourseRefDirMapper, CourseRefDir> implements CourseRefDirService {

    @Autowired
    private CourseRefDirMapper baseMapper;
    @Override
    public void save(String courseId, List<CourseRefDir> list) {

        QueryWrapper<CourseRefDir> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(CourseRefDir::getCourseId, courseId);
        this.remove(wrapper);

        if(CollectionUtils.isEmpty(list)){
            return;
        }

        this.saveBatch(list);
    }

    @Override
    public void saveNewItem(String classId, List<CourseRefDir> saveDirs) {
        saveDirs.stream().forEach(item->{
            baseMapper.saveNewItem(item);
        });
    }
}
